package updown.util;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>Title: com.damai.handler </p>
 * <p>Description:super: -  </p>
 *
 * @Author:jiangkaixin
 * @Date:2021/3/10
 * @Version: 1.0
 */
@Slf4j
public class ServerContextHolder {
    private static final ThreadLocal<ServerContext> threadLocal = new ThreadLocal<>();

    public static final ServerContext getContext(){
       ServerContext serverContext = threadLocal.get();
        if (serverContext == null) {
            log.info("[getContext] this is indicate that context is null to new one");
            serverContext = new ServerContext();
            threadLocal.set(serverContext);
        }
        return threadLocal.get();
    }

    public static final void setContext(ServerContext context) {
        threadLocal.set(context);
    }
}
